cargo: add license and license_file to cargo metadata output
authorJeremy Fitzhardinge <jsgf@fb.com>
Sun, 25 Sep 2016 21:57:51 +0000 (14:57 -0700)
committerJeremy Fitzhardinge <jsgf@fb.com>
Mon, 26 Sep 2016 02:38:27 +0000 (19:38 -0700)
src/cargo/core/package.rs
tests/metadata.rs
tests/read-manifest.rs

index c0554fbfc55a1dacea41cf09293194eca2c52bf0..da14b04fc33c6d36b0328b3cfad981a337348770 100644 (file)
@@ -29,6 +29,8 @@ struct SerializedPackage<'a> {
     name: &'a str,
     version: &'a str,
     id: &'a PackageId,
+    license: Option<&'a str>,
+    license_file: Option<&'a str>,
     source: &'a SourceId,
     dependencies: &'a [Dependency],
     targets: &'a [Target],
@@ -40,11 +42,16 @@ impl Encodable for Package {
     fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error> {
         let summary = self.manifest.summary();
         let package_id = summary.package_id();
+        let manmeta = self.manifest.metadata();
+        let license = manmeta.license.as_ref().map(String::as_ref);
+        let license_file = manmeta.license_file.as_ref().map(String::as_ref);
 
         SerializedPackage {
             name: &package_id.name(),
             version: &package_id.version().to_string(),
             id: package_id,
+            license: license,
+            license_file: license_file,
             source: summary.source_id(),
             dependencies: summary.dependencies(),
             targets: &self.manifest.targets(),
index 2f2c21056e5ee67c99ba2ebec3b0882a5c9f7daf..a180aae49a91cd3cd257bf6872b1cf687d17acc2 100644 (file)
@@ -19,6 +19,8 @@ fn cargo_metadata_simple() {
                 "id": "foo[..]",
                 "source": null,
                 "dependencies": [],
+                "license": null,
+                "license_file": null,
                 "targets": [
                     {
                         "kind": [
@@ -80,6 +82,8 @@ fn cargo_metadata_with_deps_and_version() {
                 "manifest_path": "[..]Cargo.toml",
                 "name": "baz",
                 "source": "registry+[..]",
+                "license": null,
+                "license_file": null,
                 "targets": [
                     {
                         "kind": [
@@ -109,6 +113,8 @@ fn cargo_metadata_with_deps_and_version() {
                 "manifest_path": "[..]Cargo.toml",
                 "name": "bar",
                 "source": "registry+[..]",
+                "license": null,
+                "license_file": null,
                 "targets": [
                     {
                         "kind": [
@@ -138,6 +144,8 @@ fn cargo_metadata_with_deps_and_version() {
                 "manifest_path": "[..]Cargo.toml",
                 "name": "foo",
                 "source": null,
+                "license": "MIT",
+                "license_file": null,
                 "targets": [
                     {
                         "kind": [
@@ -198,6 +206,8 @@ fn workspace_metadata() {
                 "id": "bar[..]",
                 "source": null,
                 "dependencies": [],
+                "license": null,
+                "license_file": null,
                 "targets": [
                     {
                         "kind": [ "lib" ],
@@ -214,6 +224,8 @@ fn workspace_metadata() {
                 "id": "baz[..]",
                 "source": null,
                 "dependencies": [],
+                "license": null,
+                "license_file": null,
                 "targets": [
                     {
                         "kind": [ "lib" ],
@@ -265,6 +277,8 @@ fn workspace_metadata_no_deps() {
                 "id": "bar[..]",
                 "source": null,
                 "dependencies": [],
+                "license": null,
+                "license_file": null,
                 "targets": [
                     {
                         "kind": [ "lib" ],
@@ -281,6 +295,8 @@ fn workspace_metadata_no_deps() {
                 "id": "baz[..]",
                 "source": null,
                 "dependencies": [],
+                "license": null,
+                "license_file": null,
                 "targets": [
                     {
                         "kind": [ "lib" ],
@@ -320,6 +336,8 @@ const MANIFEST_OUTPUT: &'static str=
         "id":"foo[..]0.5.0[..](path+file://[..]/foo)",
         "source":null,
         "dependencies":[],
+        "license": null,
+        "license_file": null,
         "targets":[{
             "kind":["bin"],
             "name":"foo",
index cc24f3f6c87d3600188059ca9d60744385056c2b..44f7fa6f9eae2afae0c58649f1c6b9e502834804 100644 (file)
@@ -14,6 +14,8 @@ fn read_manifest_output() -> String {
     "name":"foo",
     "version":"0.5.0",
     "id":"foo[..]0.5.0[..](path+file://[..]/foo)",
+    "license": null,
+    "license_file": null,
     "source":null,
     "dependencies":[],
     "targets":[{